package com.mc.moring.information.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.widget.NestedScrollView;

import com.google.gson.Gson;
import com.mc.moring.R;
import com.mc.moring.app.LogUtils;
import com.mc.moring.base.BaseFragment;
import com.mc.moring.base.HttpCallback;
import com.mc.moring.bean.AppKycPersonalInformacionConfig;
import com.mc.moring.bean.ZiLiPageUserDataBean;
import com.mc.moring.information.CapitalInforActivity;
import com.mc.moring.information.modle.KycModle;
import com.mc.moring.util.DateFormatUtils;
import com.mc.moring.util.PointMgr;
import com.mc.moring.util.T;
import com.mc.moring.util.TimeUtils;
import com.mc.moring.util.ToastUtils;
import com.mc.moring.view.CustomDatePicker;
import com.mc.moring.view.mailautocomplete.AutoCompleteAdapter;
import com.mc.moring.widge.IdNumEditDialog;
import com.mc.moring.widge.PersonalInfoComfirmDialog;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PersonalInformationFragment extends BaseFragment {

    NestedScrollView parent;
    EditText et_nombre;
    TextView tv_nombre;
    LinearLayout ll_nombre;
    TextView tv_nombre_error;
    View nombre_line;

    EditText et_father_surname;
    LinearLayout ll_father_surname;
    TextView tv_father_surname;
    TextView tv_father_surname_err;
    View surname_line;


    EditText et_mother_surname;
    LinearLayout ll_mother_surname;
    TextView tv_mother_surname;
    TextView tv_mother_surname_err;
    View mother_surname_line;


    EditText et_runs;
    TextView tv_runs;
    LinearLayout ll_runs;
    TextView tv_runs_err;
    View runs_line;


    LinearLayout ll_birth;
    TextView tv_birth;
    TextView et_birth;
    FrameLayout iv_birth;
    TextView tv_birth_err;
    View birth_line;


    AutoCompleteTextView et_personal_email;
    LinearLayout ll_personal_email;
    TextView tv_personal_email;

    TextView tv_personal_email_err;
    View email_line;

    ConstraintLayout cl_sexo;
    TextView tv_sexo;
    ConstraintLayout ll_sex_man;
    TextView tv_sex_man;
    ConstraintLayout ll_sex_woman;
    TextView tv_sex_woman;
    TextView tv_sexo_err;

    ConstraintLayout cl_education;
    TextView tv_education;
    ConstraintLayout tv_junior_background;
    TextView tv_junior;
    ConstraintLayout tv_preparatory_background;
    TextView tv_preparatory;
    ConstraintLayout tv_license_background;
    TextView tv_license;
    ConstraintLayout tv_learned_person_background;
    TextView tv_learned_person;
    ConstraintLayout tv_absence_background;
    TextView tv_absence;
    TextView tv_education_err;

    ConstraintLayout cl_existing_loans;
    TextView tv_has_some;
    ConstraintLayout tv_has_some_background;
    TextView tv_not_have;
    ConstraintLayout tv_not_have_background;
    TextView tv_existing_loans_err;
    TextView tv_sub_to;
    View view = null;

    int sex = 0;// 1 man 2 woman
    int hasSome = 0;
    public KycModle kycModle = null;

    private String firstName;
    private String lastName;
    private String lastMotherName;
    private String nationalId;
    private String birthday;
    private String gender = "M";
    private String educationType;
    private String email;
    private String debt = "Y", education = "F";

    private CustomDatePicker mDatePicker;

    private IdNumEditDialog mIdNumEditDialog;

    private JSONObject userFullInfoJsonObject;

    private String timeLong = "";

    private CapitalInforActivity fatherActivity;
    private AppKycPersonalInformacionConfig.UserInfoConfig userInfoConfig;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        fatherActivity = (CapitalInforActivity) activity;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        LogUtils.logE("1 page");
        view = inflater.inflate(R.layout.fragment_personal_information, container, false);
        kycModle = KycModle.Companion.getInstant();
        initView();
        initData();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtils.logE("-kyc personal -onResume");
        LogUtils.logE("-kyc personal -onResume--isVisible():" + isVisible());
        LogUtils.logE("-kyc personal -onResume--isResumed():" + isResumed());
        if (isVisible()) {
            initData();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        LogUtils.logE("-kyc personal -onHiddenChanged--hidden:" + hidden);
        if (!hidden) {
            initData();

        }
    }


    private void initDatePicker() {
        Calendar calendar = Calendar.getInstance();
        int currentYear = calendar.get(Calendar.YEAR);
        calendar.add(Calendar.YEAR, -60);
        String dateYear60 = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);

        calendar.set(Calendar.YEAR, currentYear);

        calendar.add(Calendar.YEAR, -18);
        String dateYear18 = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);

        long beginTimestamp = DateFormatUtils.date2TimeStamp(dateYear60);
        long endTimestamp = DateFormatUtils.date2TimeStamp(dateYear18);
        mDatePicker = new CustomDatePicker(getActivity(), new CustomDatePicker.Callback() {
            @Override
            public void onTimeSelected(long timestamp) {
                String formatDate = DateFormatUtils.long2Str(timestamp, false);
                String showDate = TimeUtils.date2FormatDate(formatDate);
                if (isValidBirthday(showDate)) {
                    et_birth.setText(showDate);
                } else {
                    et_birth.setText(null);
                    tv_birth_err.setVisibility(View.VISIBLE);
                    birth_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                }
            }

            @Override
            public void onTimeListened(long timestamp) {
                String formatDate = DateFormatUtils.long2Str(timestamp, false);
                String showDate = TimeUtils.date2FormatDate(formatDate);
                timeLong = changeDate(showDate);
            }
        }, beginTimestamp, endTimestamp);

        mDatePicker.setCancelable(true);

        mDatePicker.setCanShowPreciseTime(false);

        mDatePicker.setScrollLoop(false);

        mDatePicker.setCanShowAnim(false);
    }


    @Override
    public void initView() {
        findViewById();
        sexSetting();
        educationOnClick();

        et_nombre.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if (b) {
                    PointMgr.INSTANCE.sendEvent("cl_shuru_name_2_click");
                    Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_2_click");
                }
            }
        });
        noChinese(et_nombre);
        et_nombre.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence charSequence, int start, int end, Spanned spanned, int i2, int i3) {
                for (int i = start; i < end; i++) {
                    if (Character.UnicodeBlock.of(charSequence.charAt(i)) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS) {
                        return "";
                    }
                }
                return null;
            }
        }});

        et_father_surname.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if (b) {
                    PointMgr.INSTANCE.sendEvent("cl_shuru_name_3_click");
                    Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_3_click");
                }
            }
        });
        noChinese(et_father_surname);

        et_mother_surname.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if (b) {
                    PointMgr.INSTANCE.sendEvent("cl_shuru_name_4_click");
                    Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_4_click");
                }
            }
        });
        noChinese(et_mother_surname);

        et_runs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_5_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_5_click");
            }
        });
        noChinese(et_runs);
        et_runs.setFilters(new InputFilter[]{new InputFilter.LengthFilter(9)});
        iv_birth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_6_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_6_click");
                initDatePicker();
                tv_birth_err.setVisibility(View.GONE);
                birth_line.setBackgroundColor(Color.parseColor("#33000000"));
                if (!Objects.equals(timeLong, "")) {
                    mDatePicker.show(Long.parseLong(timeLong));
                } else {
                    mDatePicker.show(System.currentTimeMillis());
                }
            }
        });


        tv_runs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mIdNumEditDialog = new IdNumEditDialog(getContext());

                mIdNumEditDialog.setDialogViewOnClickListener(new IdNumEditDialog.DialogViewOnClickListener() {
                    @Override
                    public void onClickConfirm() {
                    }
                });
                mIdNumEditDialog.showToPermissionSettingDialog(getActivity());
            }
        });

        tv_has_some.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getActivity() == null) {
                    return;
                }
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_10_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_10_click");
                tv_existing_loans_err.setVisibility(View.GONE);
                hasSome = 1;
                debt = "Y";
                tv_has_some.setTextColor(Color.parseColor("#000000"));
                tv_not_have.setTextColor(Color.parseColor("#FF999999"));
                tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            }
        });
        tv_not_have.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getActivity() == null) {
                    return;
                }
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_10_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_10_click");
                tv_existing_loans_err.setVisibility(View.GONE);
                hasSome = 2;
                debt = "N";
                tv_has_some.setTextColor(Color.parseColor("#FF999999"));
                tv_not_have.setTextColor(Color.parseColor("#000000"));
                tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            }
        });
        tv_sub_to.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_11_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_11_click");
                hideErrorTip();

                String nombreString = et_nombre.getText().toString();
                if (TextUtils.isEmpty(nombreString) || hasChinese(nombreString) || nombreString.length() > 128) {
                    linearLayoutOffsetY(parent, ll_nombre);
                    tv_nombre_error.setVisibility(View.VISIBLE);
                    nombre_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }

                String fatherSurnameString = et_father_surname.getText().toString();
                if (TextUtils.isEmpty(fatherSurnameString) || hasChinese(fatherSurnameString) || fatherSurnameString.length() > 128) {
                    linearLayoutOffsetY(parent, ll_father_surname);
                    tv_father_surname_err.setVisibility(View.VISIBLE);
                    surname_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }

                String motherSurnameString = et_mother_surname.getText().toString();
                if (!TextUtils.isEmpty(motherSurnameString)) {
                    if (hasChinese(motherSurnameString) || motherSurnameString.length() > 128) {
                        linearLayoutOffsetY(parent, ll_mother_surname);
                        tv_mother_surname_err.setVisibility(View.VISIBLE);
                        mother_surname_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                        return;
                    }
                }

                String runString = et_runs.getText().toString();
                if (TextUtils.isEmpty(runString) || (runString.length() != 9 && runString.length() != 8) || !containsDigit(runString)) {
                    linearLayoutOffsetY(parent, ll_runs);
                    tv_runs_err.setVisibility(View.VISIBLE);
                    runs_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }


                String birthString = et_birth.getText().toString();
                if (TextUtils.isEmpty(birthString) || isDateCorrect(birthString) || !isValidBirthday(birthString)) {

                    linearLayoutOffsetY(parent, ll_birth);
                    tv_birth_err.setVisibility(View.VISIBLE);
                    birth_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }

                if (TextUtils.isEmpty(gender)) {
                    linearLayoutOffsetY(parent, cl_sexo);
                    tv_sexo_err.setVisibility(View.VISIBLE);
                    return;
                }

                if (TextUtils.isEmpty(educationType) || education == "F") {
                    linearLayoutOffsetY(parent, cl_education);
                    tv_education_err.setVisibility(View.VISIBLE);
                    return;
                }

                String emailString = et_personal_email.getText().toString();
                if (TextUtils.isEmpty(emailString) || !emailFormat(emailString)) {
                    linearLayoutOffsetY(parent, ll_personal_email);
                    tv_personal_email_err.setVisibility(View.VISIBLE);
                    email_line.setBackgroundColor(Color.parseColor("#4DFF3737"));
                    return;
                }

                if (TextUtils.isEmpty(debt) || hasSome == 0) {
                    linearLayoutOffsetY(parent, cl_existing_loans);
                    tv_existing_loans_err.setVisibility(View.VISIBLE);
                    return;
                }

                if (isSameUserFullInfo()) {

                    CapitalInforActivity capitalInforActivity = (CapitalInforActivity) getActivity();
                    if (capitalInforActivity != null) {
                        capitalInforActivity.onTabSelected(capitalInforActivity.TAG_INDEX_TWO);
                        capitalInforActivity.setTabIndex(1);
                    }
                } else {
                    userupdateUserInfo();
                }
            }
        });

    }

    public static boolean containsDigit(String input) {
        Pattern pattern = Pattern.compile(".*[0-9].*");
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }

    private String changeDate(String time) {
        StringBuilder finString = new StringBuilder();
        try {
            if (time.length() == 10) {
                for (int i = 0; i < 4; i++) {
                    finString.append(time.charAt(i + 6));
                }
                finString.append(time.charAt(5));
                for (int i = 0; i < 2; i++) {
                    finString.append(time.charAt(i + 3));
                }
                finString.append(time.charAt(2));
                for (int i = 0; i < 2; i++) {
                    finString.append(time.charAt(i));
                }
                finString = new StringBuilder(finString + " 12:00:00");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = sdf.parse(String.valueOf(finString));
                long timestamp = date.getTime();
                return String.valueOf(timestamp);
            }
            return time;
        } catch (Exception e) {
            e.printStackTrace();
            return time;
        }
    }

    public void hasSmome() {
        if (hasSome == 1) {
            tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
            tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        } else if (hasSome == 2) {
            tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
            tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        }

    }

    @Override
    public void initData() {
        LogUtils.logE("-kyc personal -initData--");
        getZiLiPageUserInfoConfig();
        getZiLiPageUserFullInfo();
    }


    //kelvin
    private void hideErrorTip() {
        tv_nombre_error.setVisibility(View.GONE);
        tv_father_surname_err.setVisibility(View.GONE);
        tv_mother_surname_err.setVisibility(View.GONE);
        tv_runs_err.setVisibility(View.GONE);
        tv_birth_err.setVisibility(View.GONE);
        tv_personal_email_err.setVisibility(View.GONE);
        tv_sexo_err.setVisibility(View.GONE);
        tv_education_err.setVisibility(View.GONE);
        tv_existing_loans_err.setVisibility(View.GONE);
        nombre_line.setBackgroundColor(Color.parseColor("#33000000"));
        surname_line.setBackgroundColor(Color.parseColor("#33000000"));
        mother_surname_line.setBackgroundColor(Color.parseColor("#33000000"));
        runs_line.setBackgroundColor(Color.parseColor("#33000000"));
        birth_line.setBackgroundColor(Color.parseColor("#33000000"));
        email_line.setBackgroundColor(Color.parseColor("#33000000"));
    }

    private void findViewById() {
        parent = view.findViewById(R.id.parent);
        et_nombre = view.findViewById(R.id.et_nombre);
        tv_nombre_error = view.findViewById(R.id.tv_nombre_error);
        nombre_line = view.findViewById(R.id.nombre_line);

//        et_nombre.addTextChangedListener(new CommonTextWatcher(et_nombre, tv_nombre_error));

        tv_nombre = view.findViewById(R.id.tv_nombre);
        ll_nombre = view.findViewById(R.id.ll_nombre);

        et_father_surname = view.findViewById(R.id.et_father_surname);
        tv_father_surname_err = view.findViewById(R.id.tv_father_surname_err);
        surname_line = view.findViewById(R.id.surname_line);

//        et_father_surname.addTextChangedListener(new CommonTextWatcher(et_father_surname, tv_father_surname_err));

        ll_father_surname = view.findViewById(R.id.ll_father_surname);
        tv_father_surname = view.findViewById(R.id.tv_father_surname);

        et_mother_surname = view.findViewById(R.id.et_mother_surname);
        ll_mother_surname = view.findViewById(R.id.ll_mother_surname);
        tv_mother_surname = view.findViewById(R.id.tv_mother_surname);
        tv_mother_surname_err = view.findViewById(R.id.tv_mother_surname_err);
        mother_surname_line = view.findViewById(R.id.mother_surname_line);

//        et_mother_surname.addTextChangedListener(new CommonTextWatcher(et_mother_surname, tv_mother_surname_err));

        et_runs = view.findViewById(R.id.et_runs);
        tv_runs = view.findViewById(R.id.tv_runs);
        ll_runs = view.findViewById(R.id.ll_runs);
        tv_runs_err = view.findViewById(R.id.tv_runs_err);
        runs_line = view.findViewById(R.id.runs_line);

//        et_runs.addTextChangedListener(new RunsTextWatcher(et_runs, tv_runs_err));

        ll_sex_man = view.findViewById(R.id.ll_sex_man);
        tv_sex_man = view.findViewById(R.id.tv_sex_man);
        ll_sex_woman = view.findViewById(R.id.ll_sex_woman);
        tv_sex_woman = view.findViewById(R.id.tv_sex_woman);
        cl_sexo = view.findViewById(R.id.cl_sexo);
        tv_sexo = view.findViewById(R.id.tv_sexo);
        tv_sexo_err = view.findViewById(R.id.tv_sexo_err);

        ll_birth = view.findViewById(R.id.ll_birth);
        tv_birth = view.findViewById(R.id.tv_birth);
        et_birth = view.findViewById(R.id.et_birth);
        iv_birth = view.findViewById(R.id.iv_birth);
        tv_birth_err = view.findViewById(R.id.tv_birth_err);
        birth_line = view.findViewById(R.id.birth_line);


        et_personal_email = view.findViewById(R.id.et_personal_email);

        AutoCompleteAdapter adapter = new AutoCompleteAdapter(getContext(),
                android.R.layout.simple_dropdown_item_1line);


        et_personal_email.setAdapter(adapter);

        et_nombre.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
            @Override
            public void afterTextChanged(Editable editable) {
                tv_nombre_error.setVisibility(View.GONE);
                nombre_line.setBackgroundColor(Color.parseColor("#33000000"));
            }
        });
        et_father_surname.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void afterTextChanged(Editable editable) {
                tv_father_surname_err.setVisibility(View.GONE);
                surname_line.setBackgroundColor(Color.parseColor("#33000000"));
            }
        });
        et_mother_surname.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void afterTextChanged(Editable editable) {
                tv_mother_surname_err.setVisibility(View.GONE);
                mother_surname_line.setBackgroundColor(Color.parseColor("#33000000"));
            }
        });
        et_runs.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if ( (charSequence.length() == 9 || charSequence.length() == 8) ) {
                    tv_runs_err.setVisibility(View.GONE);
                    runs_line.setBackgroundColor(Color.parseColor("#33000000"));
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {}
        });

        et_personal_email.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_9_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_9_click");
            }
        });

        et_personal_email.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence charSequence, int start, int end, Spanned spanned, int i2, int i3) {
                Log.e("----char",charSequence.toString() + "start"+ start + "end"+ end + "spanned"+ spanned + "i2"+ i2 + "i3" + i3);
                for (int i = start; i < end; i++) {
                    if (Character.UnicodeBlock.of(charSequence.charAt(i)) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS) {
                        return "";
                    }
                }
                if(charSequence.equals(" ") && i2 == 0)return "";
                return null;
            }
        }});

        et_personal_email.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
                // Filter the suggestions based on the user's input
                LogUtils.logE("onTextChanged: " + charSequence);
                String trimmedText = charSequence.toString().trim();
                if (!TextUtils.isEmpty(trimmedText)) {
                    tv_personal_email_err.setVisibility(View.GONE);
                    email_line.setBackgroundColor(Color.parseColor("#33000000"));
                }
                adapter.getFilter().filter(charSequence);
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });


        ll_personal_email = view.findViewById(R.id.ll_personal_email);
        tv_personal_email = view.findViewById(R.id.tv_personal_email);
        tv_personal_email_err = view.findViewById(R.id.tv_personal_email_err);
        email_line = view.findViewById(R.id.email_line);

        cl_education = view.findViewById(R.id.cl_education);
        tv_education = view.findViewById(R.id.tv_education);
        tv_junior = view.findViewById(R.id.tv_junior);
        tv_junior_background = view.findViewById(R.id.tv_junior_background);
        tv_preparatory = view.findViewById(R.id.tv_preparatory);
        tv_preparatory_background = view.findViewById(R.id.tv_preparatory_background);
        tv_license = view.findViewById(R.id.tv_license);
        tv_license_background = view.findViewById(R.id.tv_license_background);
        tv_absence = view.findViewById(R.id.tv_absence);
        tv_absence_background = view.findViewById(R.id.tv_absence_background);
        tv_education_err = view.findViewById(R.id.tv_education_err);
        tv_learned_person = view.findViewById(R.id.tv_learned_person);
        tv_learned_person_background = view.findViewById(R.id.tv_learned_person_background);
        cl_existing_loans = view.findViewById(R.id.cl_existing_loans);
        tv_has_some = view.findViewById(R.id.tv_has_some);
        tv_has_some_background = view.findViewById(R.id.tv_has_some_background);
        tv_not_have = view.findViewById(R.id.tv_not_have);
        tv_not_have_background = view.findViewById(R.id.tv_not_have_background);
        tv_existing_loans_err = view.findViewById(R.id.tv_existing_loans_err);

        tv_sub_to = view.findViewById(R.id.tv_sub_to);
    }

    @SuppressLint("ResourceAsColor")
    public void sexSetting() {
        if (getActivity() == null) {
            return;
        }
        if (sex == 1) {
            ll_sex_man.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
            ll_sex_woman.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            tv_sex_man.setTextColor(Color.parseColor("#000000"));
            tv_sex_woman.setTextColor(Color.parseColor("#FF666666"));
        } else if (sex == 2) {
            ll_sex_woman.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
            ll_sex_man.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            tv_sex_woman.setTextColor(Color.parseColor("#000000"));
            tv_sex_man.setTextColor(Color.parseColor("#FF666666"));
        } else {
            ll_sex_woman.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            ll_sex_man.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            tv_sex_man.setTextColor(Color.parseColor("#FF666666"));
            tv_sex_woman.setTextColor(Color.parseColor("#FF666666"));
        }
        ll_sex_man.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getActivity() == null) {
                    return;
                }
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_7_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_7_click");
                tv_sexo_err.setVisibility(View.GONE);
                sex = 1;
                ll_sex_man.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                ll_sex_woman.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
                gender = "M";
                tv_sex_man.setTextColor(Color.parseColor("#000000"));
                tv_sex_woman.setTextColor(Color.parseColor("#FF666666"));
            }
        });
        ll_sex_woman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getActivity() == null) {
                    return;
                }
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_7_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_7_click");
                tv_sexo_err.setVisibility(View.GONE);
                sex = 2;
                ll_sex_woman.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                ll_sex_man.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
                gender = "F";
                tv_sex_woman.setTextColor(Color.parseColor("#000000"));
                tv_sex_man.setTextColor(Color.parseColor("#FF666666"));
            }
        });
    }

    public void educationOnClick() {

//        "Primaria
//        Preparatoria
//        Licenciatura
//        Maestría/Doctorado
//        Ninguno"
        tv_junior.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_8_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_8_click");
                educationType = tv_junior.getText().toString();
                education = "A";
                educationUiUpdata(tv_junior_background);
                tv_junior.setTextColor(Color.parseColor("#000000"));
                tv_preparatory.setTextColor(Color.parseColor("#FF999999"));
                tv_license.setTextColor(Color.parseColor("#FF999999"));
                tv_learned_person.setTextColor(Color.parseColor("#FF999999"));
                tv_absence.setTextColor(Color.parseColor("#FF999999"));
            }
        });

        tv_preparatory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_8_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_8_click");
                educationType = tv_preparatory.getText().toString();
                education = "B";
                educationUiUpdata(tv_preparatory_background);
                tv_junior.setTextColor(Color.parseColor("#FF999999"));
                tv_preparatory.setTextColor(Color.parseColor("#000000"));
                tv_license.setTextColor(Color.parseColor("#FF999999"));
                tv_learned_person.setTextColor(Color.parseColor("#FF999999"));
                tv_absence.setTextColor(Color.parseColor("#FF999999"));
            }
        });

        tv_license.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_8_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_8_click");
                educationType = tv_license.getText().toString();
                education = "C";
                educationUiUpdata(tv_license_background);
                tv_junior.setTextColor(Color.parseColor("#FF999999"));
                tv_preparatory.setTextColor(Color.parseColor("#FF999999"));
                tv_license.setTextColor(Color.parseColor("#000000"));
                tv_learned_person.setTextColor(Color.parseColor("#FF999999"));
                tv_absence.setTextColor(Color.parseColor("#FF999999"));
            }
        });

        tv_learned_person.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_8_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_8_click");
                educationType = tv_learned_person.getText().toString();
                education = "D";
                educationUiUpdata(tv_learned_person_background);
                tv_junior.setTextColor(Color.parseColor("#FF999999"));
                tv_preparatory.setTextColor(Color.parseColor("#FF999999"));
                tv_license.setTextColor(Color.parseColor("#FF999999"));
                tv_learned_person.setTextColor(Color.parseColor("#000000"));
                tv_absence.setTextColor(Color.parseColor("#FF999999"));
            }
        });

        tv_absence.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PointMgr.INSTANCE.sendEvent("cl_shuru_name_8_click");
                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_8_click");
                educationType = tv_absence.getText().toString();
                education = "E";
                educationUiUpdata(tv_absence_background);
                tv_junior.setTextColor(Color.parseColor("#FF999999"));
                tv_preparatory.setTextColor(Color.parseColor("#FF999999"));
                tv_license.setTextColor(Color.parseColor("#FF999999"));
                tv_learned_person.setTextColor(Color.parseColor("#FF999999"));
                tv_absence.setTextColor(Color.parseColor("#000000"));
            }
        });
    }

    public void educationUiUpdata(View view) {
        if (getActivity() == null) {
            return;
        }
        tv_education_err.setVisibility(View.GONE);
        tv_junior_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        tv_preparatory_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        tv_license_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        tv_learned_person_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        tv_absence_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
        view.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
    }


    private void getZiLiPageUserInfoConfig() {
        Map<String, String> params = new HashMap<String, String>();
        fatherActivity.showLoading();
        kycModle.getZiLiPageUserInfoConfig(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                CapitalInforActivity capitalInforActivity = (CapitalInforActivity) getActivity();
                if (capitalInforActivity != null) {
                    capitalInforActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                JSONObject jsonObject = new JSONObject(data);
                                if (kycModle.getStringToJson(jsonObject, "code").equals("0000")) {
                                    AppKycPersonalInformacionConfig applicationUserInfoConfigBean = new AppKycPersonalInformacionConfig();
                                    applicationUserInfoConfigBean.initConfigData(jsonObject.optJSONObject("data"));
                                    userInfoConfig = applicationUserInfoConfigBean.getUserInfoConfig();
                                    if (applicationUserInfoConfigBean.getUserInfoConfig() != null) {
                                        LogUtils.logE("--- userInfoConfig.getEducationDegree():" + userInfoConfig.getEducationDegree());
                                        isShowView(userInfoConfig.getFirstName(), ll_nombre, tv_nombre, "Nombre");
                                        isShowView(userInfoConfig.getLastName(), ll_father_surname, tv_father_surname, "Apellido paterno");
                                        isShowView(userInfoConfig.getLastMotherName(), ll_mother_surname, tv_mother_surname, "Apellido materno");
                                        isShowView(userInfoConfig.getNationalId(), ll_runs, tv_runs, "Número de RUN");
                                        isShowView(userInfoConfig.getGender(), cl_sexo, tv_sexo, "Sexo");
                                        isShowView(userInfoConfig.getEducationDegree(), cl_education, tv_education, "Nivel de educación");
                                        isShowView(userInfoConfig.getEmail(), ll_birth, tv_birth, "Fecha de nacimiento");
                                        isShowView(userInfoConfig.getEmail(), ll_personal_email, tv_personal_email, "Correo electrónico personal");
                                    }
                                } else {
                                    ToastUtils.showShort(getActivity(), kycModle.getStringToJson(jsonObject, "msg"));
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                fatherActivity.hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {
                fatherActivity.hideLoading();
            }
        });

    }

    private void getZiLiPageUserFullInfo() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("custId", ZiLiPageUserDataBean.getInstance().getCustomerId());
        fatherActivity.showLoading();
        kycModle.getZiLiPageUserFullInfo(params, new HttpCallback() {
            @Override
            public void onSuccess(@NonNull String data) {
                CapitalInforActivity capitalInforActivity = (CapitalInforActivity) getActivity();
                if (capitalInforActivity != null) {
                    capitalInforActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                userFullInfoJsonObject = new JSONObject(data);
                                if (kycModle.isSuccess(userFullInfoJsonObject)) {
                                    LogUtils.logE("历史信息>" + userFullInfoJsonObject.toString());
                                    getActivity().runOnUiThread(new Runnable() {
                                        @Override
                                        public void run() {
                                            showHistoryData(userFullInfoJsonObject.optJSONObject("data"));
                                        }
                                    });
                                } else {
                                    T.showShort(getActivity(), kycModle.getStringToJson(userFullInfoJsonObject, "msg"));
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                }
                fatherActivity.hideLoading();
            }

            @Override
            public void onFaill(@NonNull String e) {
                fatherActivity.hideLoading();
            }
        });
    }

    private void showHistoryData(JSONObject jsonObject) {
        firstName = jsonObject.optString("firstName");
        lastName = jsonObject.optString("lastName");
        lastMotherName = jsonObject.optString("lastMotherName");
        nationalId = jsonObject.optString("nationalId");
        birthday = jsonObject.optString("birthday");
        gender = jsonObject.optString("gender");
        debt = jsonObject.optString("debt");
        email = jsonObject.optString("email");
        education = jsonObject.optString("educationType");
        if (!TextUtils.isEmpty(debt) && !debt.equals("null")) {
            if (debt.equals("Y")) {
                tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            } else {
                tv_not_have_background.setBackground(getActivity().getDrawable(R.drawable.bg_gradient_65ff96_00daf7_corner_0));
                tv_has_some_background.setBackground(getActivity().getDrawable(R.drawable.bg_frame_4d333333_corner_8));
            }
        }
        if (!TextUtils.isEmpty(education) && !education.equals("null")) {
            if (education.equals("A")) {
                educationUiUpdata(tv_junior_background);
                educationType = tv_junior.getText().toString();
                tv_junior.setTextColor(Color.parseColor("#999999"));
            } else if (education.equals("B")) {
                educationUiUpdata(tv_preparatory_background);
                educationType = tv_preparatory.getText().toString();
                tv_preparatory.setTextColor(Color.parseColor("#999999"));
            } else if (education.equals("C")) {
                educationUiUpdata(tv_license_background);
                educationType = tv_license.getText().toString();
                tv_license.setTextColor(Color.parseColor("#999999"));
            } else if (education.equals("D")) {
                educationUiUpdata(tv_learned_person_background);
                educationType = tv_learned_person.getText().toString();
                tv_learned_person.setTextColor(Color.parseColor("#999999"));
            } else {
                educationUiUpdata(tv_absence_background);
                educationType = tv_absence.getText().toString();
                tv_absence.setTextColor(Color.parseColor("#999999"));
            }
        }
        if (!TextUtils.isEmpty(firstName) && !firstName.equals("null")) {
            et_nombre.setText(firstName);
        }
        if (!TextUtils.isEmpty(lastName) && !lastName.equals("null")) {
            et_father_surname.setText(lastName);
        }
        if (!TextUtils.isEmpty(lastMotherName) && !lastMotherName.equals("null")) {
            et_mother_surname.setText(lastMotherName);
        }
        if (!TextUtils.isEmpty(nationalId) && !nationalId.equals("null")) {
            et_runs.setText(nationalId);
            et_runs.setFocusable(false);
            et_runs.setFocusableInTouchMode(false);
            et_runs.setEnabled(false);
            et_runs.setTextColor(Color.parseColor("#999999"));
        }
        if (!TextUtils.isEmpty(birthday) && !birthday.equals("null")) {
            if (birthday.contains("/")) {
                et_birth.setText(TimeUtils.upload2dateFormatDate(birthday));
            } else {
                et_birth.setText(birthday);
            }
        }
        if (!TextUtils.isEmpty(email) && !email.equals("null")) {
            et_personal_email.setText(email);
            et_birth.setEnabled(false);
        }
        if (!TextUtils.isEmpty(gender) && !gender.equals("null")) {
            if (TextUtils.equals(gender, "M")) {
                sex = 1;
                gender = "M";
                sexSetting();
            } else if (TextUtils.equals(gender, "F")) {
                gender = "F";
                sex = 2;
                sexSetting();
            }
        }
        if (!TextUtils.isEmpty(debt) && !debt.equals("null")) {
            if (TextUtils.equals(debt, "Y")) {
                debt = "Y";
                hasSome = 1;
                hasSmome();
            } else if (TextUtils.equals(debt, "N")) {
                debt = "N";
                hasSome = 2;
                hasSmome();
            }
        }
    }

    private String getEducationType() {
        if (educationType == tv_junior.getText().toString()) {
            return "A";
        } else if (educationType == tv_preparatory.getText().toString()) {
            return "B";
        } else if (educationType == tv_license.getText().toString()) {
            return "C";
        } else if (educationType == tv_learned_person.getText().toString()) {
            return "D";
        } else if (educationType == tv_absence.getText().toString()) {
            return "E";
        } else {
            return "null";
        }
    }

    private String getHaveDebt() {
        if (hasSome == 1) {
            return "Y";
        } else if (hasSome == 2) {
            return "N";
        } else {
            return "null";
        }
    }

    private String getGender() {
        if (sex == 1) {
            return "M";
        } else if (sex == 2) {
            return "F";
        } else {
            return "null";
        }

    }

    private Boolean isSameUserFullInfo() {
        boolean isSame = true;
        if (userFullInfoJsonObject != null) {
            JSONObject dataObject = userFullInfoJsonObject.optJSONObject("data");
            String firstName = dataObject.optString("firstName");
            String lastName = dataObject.optString("lastName");
            String lastMotherName = dataObject.optString("lastMotherName");
            String nationalId = dataObject.optString("nationalId");
            String birthday = dataObject.optString("birthday");
            String gender = dataObject.optString("gender");
            String debt = dataObject.optString("debt");
            String email = dataObject.optString("email");
            String education = dataObject.optString("educationType");
            LogUtils.logE("---firstName:" + firstName);
            LogUtils.logE("-et--firstName:" + et_nombre.getText());
            if (TextUtils.isEmpty(firstName) || firstName.equals("null") || !TextUtils.equals(firstName, et_nombre.getText())) {
                isSame = false;
            }
            LogUtils.logE("---lastName:" + lastName);
            LogUtils.logE(" -et-lastName:" + et_father_surname.getText());
            if (TextUtils.isEmpty(lastName) || lastName.equals("null") || !TextUtils.equals(lastName, et_father_surname.getText())) {
                isSame = false;
            }
            LogUtils.logE("---lastMotherName:" + lastMotherName);
            LogUtils.logE("-et--lastMotherName:" + et_mother_surname.getText());
            if (!TextUtils.isEmpty(lastMotherName) && !lastMotherName.equals("null")) {
                if (!TextUtils.equals(lastMotherName, et_mother_surname.getText())) {
                    isSame = false;
                }
            }
            LogUtils.logE("---nationalId:" + nationalId);
            LogUtils.logE("--et-nationalId:" + et_runs.getText());
            if (TextUtils.isEmpty(nationalId) || nationalId.equals("null") || !TextUtils.equals(nationalId, et_runs.getText())) {
                isSame = false;
            }
            LogUtils.logE("---birthday:" + birthday);
            LogUtils.logE("-et--birthday:" + et_birth.getText());
            String fromatBirthDay = TimeUtils.date2UploadFormatDate(et_birth.getText().toString());
            if (TextUtils.isEmpty(birthday) || birthday.equals("null") || !TextUtils.equals(birthday, fromatBirthDay)) {
                isSame = false;
            }
            LogUtils.logE("---gender:" + gender);
            LogUtils.logE("--et-gender:" + getGender());
            if (TextUtils.isEmpty(gender) || gender.equals("null") || !TextUtils.equals(gender, getGender())) {
                isSame = false;
            }
            LogUtils.logE("---debt:" + debt);
            LogUtils.logE("-et--debt:" + getHaveDebt());
            if (TextUtils.isEmpty(debt) || debt.equals("null") || !TextUtils.equals(debt, getHaveDebt())) {
                isSame = false;
            }
            LogUtils.logE("---email:" + email);
            LogUtils.logE("-et--email:" + et_personal_email.getText());
            if (TextUtils.isEmpty(email) || email.equals("null") || !TextUtils.equals(email, et_personal_email.getText())) {
                isSame = false;
            }
            LogUtils.logE("---education:" + education);
            LogUtils.logE(" -et--education:" + getEducationType());
            if (TextUtils.isEmpty(education) || education.equals("null") || !TextUtils.equals(education, getEducationType())) {
                isSame = false;
            }

        } else {
            isSame = false;
        }


        return isSame;
    }

    private void userupdateUserInfo() {
        PersonalInfoComfirmDialog myDialog = new PersonalInfoComfirmDialog(getActivity(), et_runs.getText().toString().trim());
        CapitalInforActivity capitalInforActivity = (CapitalInforActivity) getActivity();
        if (capitalInforActivity != null) {
            myDialog.setDialogViewOnClickListener(new PersonalInfoComfirmDialog.DialogViewOnClickListener() {
                @Override
                public void onClickConfirm() {
                    LogUtils.logE("myDialog onClickConfirm");
                    Map<String, String> params = new HashMap<String, String>();
                    firstName = et_nombre.getText().toString();
                    lastName = et_father_surname.getText().toString();
                    lastMotherName = et_mother_surname.getText().toString();
                    nationalId = et_runs.getText().toString();
                    birthday = TimeUtils.date2UploadFormatDate(et_birth.getText().toString());


                    email = et_personal_email.getText().toString();
                    params.put("firstName", firstName);
                    params.put("lastName", lastName);
                    params.put("lastMotherName", lastMotherName);
                    params.put("nationalId", nationalId);
                    params.put("birthday", birthday);
                    params.put("gender", gender);
                    params.put("educationType", education);
                    params.put("email", email);
                    params.put("debt", debt);
                    LogUtils.logE("page 1 params>" + new Gson().toJson(params));
                    fatherActivity.showLoading();
                    kycModle.updateZiLiPageUserInfo(params, new HttpCallback() {
                        @Override
                        public void onSuccess(@NonNull String data) {
                            try {
                                PointMgr.INSTANCE.sendEvent("cl_shuru_name_12_click");
                                Log.e("PointMgr.INSTANCE.sendEvent", "cl_shuru_name_12_click");
                                JSONObject jsonObject = new JSONObject(data);
                                if (kycModle.isSuccess(jsonObject)) {
                                    if (capitalInforActivity != null) {
                                        capitalInforActivity.runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                capitalInforActivity.onTabSelected(capitalInforActivity.TAG_INDEX_TWO);
                                                capitalInforActivity.setTabIndex(1);
                                                myDialog.dismiss();
                                            }
                                        });
                                    }


                                } else {
                                    if (capitalInforActivity != null) {
                                        capitalInforActivity.runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                T.showShort(getActivity(), kycModle.getStringToJson(jsonObject, "msg"));
                                            }
                                        });
                                    }

                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            fatherActivity.hideLoading();
                        }

                        @Override
                        public void onFaill(@NonNull String e) {
                            fatherActivity.hideLoading();
                        }
                    });
                }

                @Override
                public void onClickCancel() {
                    LogUtils.logE("myDialog onClickCancel");
                    myDialog.dismiss();
                }
            });
            myDialog.showToPermissionSettingDialog(getActivity());
        }


    }


    private void close() {
        if (getActivity().getCurrentFocus() == null) {
            return;
        }
        ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

    private class CommonTextWatcher implements TextWatcher {
        private TextView errText;

        private EditText editText;

        public CommonTextWatcher(EditText editText, TextView errText) {
            this.errText = errText;
            this.editText = editText;
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    String trimmedText = charSequence.toString().trim();

                    if (!trimmedText.isEmpty()) {
                        clearEditTextError();
                    }

                    if (startsWithSpace(charSequence)) {
                        editText.setText(trimmedText);
                        editText.setSelection(trimmedText.length());
                    } else {
                        clearEditTextError();
                    }

                    if (charSequence.length() > 128) {
                        errText.setVisibility(View.VISIBLE);
                    } else {
                        clearEditTextError();
                    }

                    if (hasChinese(charSequence.toString())) {
                        errText.setVisibility(View.VISIBLE);
                    } else {
                        clearEditTextError();
                    }
                }
            });
        }

        @Override
        public void afterTextChanged(Editable editable) {
            for (int i = 0; i < editable.length(); i++) {
                char c = editable.charAt(i);
                if (hasChinese(String.valueOf(c))) {
                    editable.delete(i, i + 1);
                }
            }
        }


        private void clearEditTextError() {
            errText.setVisibility(View.GONE);
        }

        private boolean startsWithSpace(CharSequence charSequence) {
            return charSequence.length() > 0 && charSequence.charAt(0) == ' ';
        }
    }

    private class RunsTextWatcher implements TextWatcher {
        private TextView errText;

        private EditText editText;

        public RunsTextWatcher(EditText editText, TextView errText) {
            this.errText = errText;
            this.editText = editText;
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int before, int count) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {

            String trimmedText = charSequence.toString().trim();


            if (!trimmedText.isEmpty()) {
                clearEditTextError();
            }


            if (startsWithSpace(charSequence)) {

                editText.setText(trimmedText);
                editText.setSelection(trimmedText.length());
            } else {
                clearEditTextError();
            }


            if (charSequence.length() > 9 || charSequence.length() < 8) {
                errText.setVisibility(View.VISIBLE);
            } else {
                clearEditTextError();
            }


            if (hasChinese(charSequence.toString())) {
                errText.setVisibility(View.VISIBLE);
            } else {
                clearEditTextError();
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }

        private void clearEditTextError() {

            errText.setVisibility(View.GONE);
        }

        private boolean startsWithSpace(CharSequence charSequence) {

            return charSequence.length() > 0 && charSequence.charAt(0) == ' ';
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        fatherActivity.hideLoading();
    }

    private void noChinese(EditText editText) {
        editText.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence charSequence, int start, int end, Spanned spanned, int i2, int i3) {
                for (int i = start; i < end; i++) {
                    if (Character.UnicodeBlock.of(charSequence.charAt(i)) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS) {
                        return "";
                    }
                }
                return null;
            }
        }});
    }
}
